﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace qf_cms.admin
{
	public partial class add_column : SessionPage
	{
		LogicLayer mgr = new LogicLayer();
		protected string id = "", pid = "", tip = "", colName="";

		protected void Page_Load(object sender, EventArgs e)
		{
			id = Request.QueryString["id"] + "";
			pid = Request.QueryString["pid"] + "";

			if (!string.IsNullOrEmpty(id))
			{
				CMS_Columns col = mgr.GetCMS_Columns(id);
				if(col != null)
					colName = col.ColumnName;
			}

			if (IsPostBack)
			{
				if (string.IsNullOrEmpty(id))
				{ 
					//add
					CMS_Columns col = new CMS_Columns();
					col.ColumnID = mgr.GenerateColumnID(pid);
					col.ColumnName = Request.Form["ColumnName"];
					col.ParentID = pid;
					col.SequenceNo = col.ColumnID;
					if (mgr.AddCMS_Columns(col))
					{
						Response.Redirect("columnGeneral.aspx?id=" + pid);
					}
					else
						tip = "保存失败!";
				}
				else
				{
					//edit
					CMS_Columns col = mgr.GetCMS_Columns(id);
					col.ColumnName = Request.Form["ColumnName"];
					if (mgr.UpdateCMS_Columns(col))
						Response.Redirect("columnGeneral.aspx?id=" + pid);
					else
						tip = "保存失败!";
				}
			}
		}
	}
}